package com.device.controller;

import com.device.entity.User;
import com.device.util.DesUtil;
import com.device.util.Result;
import com.device.util.Message;
import com.device.util.CookieUtil;
import com.alibaba.fastjson.JSONObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lgb
 * @date 2020-10-15
 * @return 用户管理
 **/
@RestController
@RequestMapping("/user")
public class UserController extends BaseController{

	@PostMapping(value="login")
	public Message login(String username,String password){
		if(username.equals("admin")&&password.equals("12345")){
			User user = new User();
			user.setUsername(username);user.setPassword(password);
			String infoString = JSONObject.toJSONString(user);
			infoString = DesUtil.encrypt(infoString);
			CookieUtil.addCookie(response,"adminInfo",infoString,-1);//设置-1表示关闭就过期
			return Message.done(user);
		}
		return Message.fail("用户或者密码错误!");
	}
	
	/**
	 * @return 退出
	 **/
	@GetMapping("logout")
	public Result logout() {
        return new Result().success();
	}
}